class MyTicker {
	private static timesArr:Array<any> = [];

	/** 程序帧数自增值 */
	public static tick:number;

	public static run(main:egret.DisplayObject):void{
		main.addEventListener(egret.Event.ENTER_FRAME, MyTicker.onFrame, this);
	}

	private static last:number = 0;
	private static onFrame():void{
		MyTicker.tick++;
		var t:number = egret.getTimer();
		var n:number = t - MyTicker.last;
		if(n > 1000){
			MyTicker.runTimer(Math.floor(n / 1000));
			MyTicker.last = t;
		}
	}

	private static runTimer(count:number):void{
		for(var j = 0; j < MyTicker.timesArr.length; j++){
			var obj:any = MyTicker.timesArr[j];
			for(var i = 0; i < count; i++){
				obj.func.call(obj.ths);
			}
		}
	}

	/**
	 * 添加每秒执行的函数，已经做了休眠补偿的
	 */
	public static addTimer(func:any, ths):void{
		var len:number = MyTicker.timesArr.length;
		for(var i = 0; i < len; i++){
			var obj:any = MyTicker.timesArr[i];
			if(obj.func == func && obj.ths == ths){
				return;
			}
		}
		MyTicker.timesArr.push({func: func, ths: ths});
	}

	public static removeTimer(func:any, ths:any):void{
		var len:number = MyTicker.timesArr.length;
		for(var i = 0; i < len; i++){
			var obj:any = MyTicker.timesArr[i];
			if(obj.func == func && obj.ths == ths){
				MyTicker.timesArr.splice(i, 1);
				break;
			}
		}
	}
}